/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rom;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import rom.character.Gender;
import rom.character.Job;
import rom.character.Upper;
import rom.factory.ItemFactory;
import rom.item.Item;
import rom.item.ItemLocation;
import rom.item.ItemType;
import rom.script.Bonus;
import rom.script.Script;
import rom.script.Variable;

/**
 *
 * @author Luis
 */
public class ROM {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here        
        Item item = new Item();
        
        item.setId(100);
        item.seteName("comb");
        item.setjName("comb");
        item.setItemType(new ItemType(ItemType.MISC));
        item.setSalePrice(100);
        item.setPurchasePrice(1000);
        item.setWeight(10);
        item.setAtack(50);
        item.setDefense(0);
        item.setAtackRange(2);
        item.setSlot(4);
        item.setJob(new Job(Job.NOVICE));
        item.setUpper(new Upper(Upper.NORMAL));
        item.setGender(new Gender(Gender.BOTH));
        item.setItemLocation(new ItemLocation(ItemLocation.LEFT_HAND));
        item.setWeaponLevel(6);
        item.setEquipLevel(0);
        item.setRefineable(Boolean.TRUE);
        item.setViewId(20001);
        
        Variable variable = new Variable();
        variable.setName("n");
        variable.setValue("10");
        Variable variable1 = new Variable();
        variable1.setName("r");
        variable1.setValue("15");
        Bonus bonus = new Bonus();
        bonus.setBonus("hp n,r");
        bonus.setVar(variable);
        bonus.setVar(variable1);
        bonus.set();
        
        item.setScript(new Script(bonus));
        //item.setOnEquipScript(new Script("{equip}"));
        //item.setOnUnequipScript(new Script("{un-equip}"));      
        
        ItemFactory factory = new ItemFactory();
        
        factory.addItem(item);
        
        try {
            factory.saveItem(factory.getItem(100), new File("c:/item.item"));
        } catch (IOException ex) {
            Logger.getLogger(ROM.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        try {
            Item readItem = factory.readItem(new File("c:/item.item"));
            System.out.println(readItem + " SIZE " + factory.size());
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ROM.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException | ClassNotFoundException ex) {
            Logger.getLogger(ROM.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
